<!--户信息-->
<template>
    <div class="page_accoutInfo">
        <common-header :title="'户信息'">
            <span slot="overwrite-left"></span>
        </common-header>
        <div class="pages-main" style="height: calc( 100vh - 45px)">
            <div class="every-info" v-for="(item,index) in lists">
                <div class="info-title">
                    <div class=" every-block-padding">
                        <img :src="item.firstImg" alt="" @click="goDetail(index,item)"/>
                        <div class="title-text translateBlock">{{item.title}}</div>
                        <img v-if="item.isOpen" src="../../../static/images/down-arrow.png"
                             @click="item.isOpen = !item.isOpen"/>
                        <img v-else src="../../../static/images/up-arrow.png" @click="item.isOpen = !item.isOpen"/>
                    </div>
                </div>
                <div v-show="item.isOpen" class="item-info">
                    <div v-show="index === 0 || index === 1">
                        <div class="item-item every-block-padding" v-for="i in item.children">
                            <div class="translateBlock" style="width:2rem;">{{i.label}}</div>
                            <div class="translateBlock" style="width: 7rem;text-align: right;line-height: 0.5rem;">
                                {{i.value}}
                            </div>
                        </div>
                    </div>
                    <div v-show="item.title === '土地信息'">
                        <div class="item-item every-block-padding" v-for="i in arableLand">
                            <div>
                                <div class="translateBlock">类型：{{i.transfertype === 1 ? '耕地' : '林地'}}</div>
                                <div class="translateBlock" style="float:right;">流转面积（亩）：{{i.transferarea}}</div>
                            </div>
                            <div>
                                流转金额（元/年）：{{i.transferoffset}}
                            </div>
                            <div style="text-align: center;">
                                <div class="translateBlock land-btn" @click="goDetail(2,i)">编辑</div>
                                <div class="translateBlock land-btn" @click="deleteInfo('arableLand',i)">删除</div>
                            </div>
                        </div>
                    </div>
                    <div v-show="item.title === '征地情况'">
                        <div class="item-item every-block-padding" v-for="i in requisitionland">
                            <div>
                                <div class="translateBlock">类型：征地</div>
                                <div class="translateBlock" style="float:right;">征地金额（元）：{{i.expropriationoffset}}</div>
                            </div>
                            <div>
                                <div class="translateBlock">征地时间：{{i.expropriationtime}}</div>
                                <div class="translateBlock" style="float:right;">补偿发放时间：{{i.offsetsenttime}}</div>
                            </div>
                            <div style="text-align: center;">
                                <div class="translateBlock land-btn" @click="goDetail(3,i)">编辑</div>
                                <div class="translateBlock land-btn" @click="deleteInfo('arableLand',i)">删除</div>
                            </div>
                        </div>
                    </div>
                    <div v-show="item.title === '复垦情况'">
                        <div class="item-item every-block-padding" v-for="i in refarmingInfoList">
                            <div>
                                <div class="translateBlock">复垦面积(亩)：{{i.refarmingarea}}</div>
                                <div class="translateBlock" style="float:right;">复垦补助(元)：{{i.refarmingamount}}</div>
                            </div>
                            <div>
                                <div class="translateBlock">补偿发放时间：{{i.sendtime}}</div>
                            </div>
                            <div style="text-align: center;">
                                <div class="translateBlock land-btn" @click="goDetail(4,i)">编辑</div>
                                <div class="translateBlock land-btn" @click="deleteInfo('refarmingInfoList',i)">删除</div>
                            </div>
                        </div>
                    </div>
                    <div v-show="item.title === '房屋信息'">
                        <div class="item-item every-block-padding" v-for="i in houseBaseInfoList">
                            <div>
                                <div class="translateBlock">所在区域：{{i.villagename}}</div>
                                <div class="translateBlock" style="float:right;">房屋类型：{{i.housetype == 1 ? '自建住房' :
                                    i.housetype == 2 ? '安置住房' : i.housetype == 3 ? '商品住房' : '其他'}}
                                </div>
                            </div>
                            <div>
                                <div class="translateBlock">购/建时间：{{i.buildingtime}}</div>
                            </div>
                            <div style="text-align: center;">
                                <div class="translateBlock land-btn" @click="goDetail(5,i)">编辑</div>
                                <div class="translateBlock land-btn" @click="deleteInfo('houseBaseInfoList',i)">删除</div>
                            </div>
                        </div>
                    </div>
                    <div v-show="item.title === '产业信息'">
                        <div class="item-item every-block-padding">
                            <div class="translateBlock">是否有果园：</div>
                            <div class="translateBlock" style="float:right;">{{lists[6].children[0].value}}</div>
                        </div>
                        <div v-show="lists[6].children[0].value === '是'">

                            <div class="item-item every-block-padding">
                                <div class="translateBlock">种植面积(亩)：</div>
                                <div class="translateBlock" style="float:right;">{{lists[6].children[1].value}}</div>
                            </div>
                            <div class="item-item every-block-padding">
                                <div class="translateBlock">种植作物：</div>
                                <div class="translateBlock" style="float:right;">{{lists[6].children[2].value}}</div>
                            </div>
                            <div class="item-item every-block-padding">
                                <div class="translateBlock">年产值(元)：</div>
                                <div class="translateBlock" style="float:right;">{{lists[6].children[3].value}}</div>
                            </div>
                        </div>
                        <div class="item-item every-block-padding">
                            <div class="translateBlock">是否经营户：</div>
                            <div class="translateBlock" style="float:right;">{{lists[6].children[4].value}}</div>
                        </div>
                        <div v-show="lists[6].children[4].value === '是'">
                            <div class="item-item every-block-padding">
                                <div class="translateBlock">经营项目：</div>
                                <div class="translateBlock" style="float:right;">{{lists[6].children[5].value}}</div>
                            </div>
                            <div class="item-item every-block-padding">
                                <div class="translateBlock">床位数量：</div>
                                <div class="translateBlock" style="float:right;">{{lists[6].children[6].value}}</div>
                            </div>
                            <div class="item-item every-block-padding">
                                <div class="translateBlock">年产值(元)：</div>
                                <div class="translateBlock" style="float:right;">{{lists[6].children[7].value}}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div v-transfer-dom>
                <confirm v-model="isShowDeleteDialog"
                         :title="'确认删除框'"
                         @on-cancel="onCancel"
                         @on-confirm="onConfirm">
                    <p style="text-align:center;">您确定要删除该数据吗？</p>
                </confirm>
            </div>
        </div>
    </div>
</template>

<script>
    import resident from '../../services/resident'

    export default {
        name: "accoutInfo",
        components: {},
        data() {
            return {
                isShowDeleteDialog: this.isShowDeleteDialog,
                familyid: this.$route.query.familyid,
                familyBaseInfo: null,
                lists: [
                    {
                        firstImg: require('../../../static/images/edit.png'), title: '基本信息', isOpen: true, children: [
                            {label: '户主姓名', 'key': 'residentsname', value: ''},
                            {label: '身份证号', 'key': 'residentidcardnumber', value: ''},
                            {label: '户口编号', 'key': 'familycode', value: ''},
                            {label: '户籍地', 'key': 'villagename', value: ''},
                            {label: '具体地址', 'key': 'houseaddress', value: ''},
                        ]
                    },
                    {
                        firstImg: require('../../../static/images/edit.png'),
                        title: '水电气通讯',
                        isOpen: false,
                        children: [
                            {label: '饮水情况', 'key': 'drinkinfo', value: ''},
                            {label: '通电情况', 'key': 'powerinfo', value: ''},
                            {label: '通气情况', 'key': 'gasinfo', value: ''},
                            {label: '道路情况', 'key': 'loadinfo', value: ''},
                            {label: '通讯覆盖', 'key': 'correspondinfo', value: ''},
                        ]
                    },
                    {
                        firstImg: require('../../../static/images/icon-add.png'),
                        title: '土地信息',
                        isOpen: false,
                        children: []
                    },
                    {
                        firstImg: require('../../../static/images/icon-add.png'),
                        title: '征地情况',
                        isOpen: false,
                        children: []
                    },
                    {
                        firstImg: require('../../../static/images/icon-add.png'),
                        title: '复垦情况',
                        isOpen: false,
                        children: []
                    },
                    {
                        firstImg: require('../../../static/images/icon-add.png'),
                        title: '房屋信息',
                        isOpen: false,
                        children: []
                    },
                    {
                        firstImg: require('../../../static/images/edit.png'), title: '产业信息', isOpen: false, children: [
                            {label: '是否有果园', 'key': 'hasgarden', value: ''},
                            {label: '面积(亩)', 'key': 'gardenarea', value: ''},
                            {label: '种植作物', 'key': 'crop', value: ''},
                            {label: '年产值(元)', 'key': 'gardengdp', value: ''},
                            {label: '是否经营户', 'key': 'hadbusiness', value: ''},
                            {label: '经营项目', 'key': 'businesscontent', value: ''},
                            {label: '床位数量', 'key': 'bednumber', value: ''},
                            {label: '年产值(元)', 'key': 'businessgdp', value: ''},
                        ]
                    },
                ],
                requisitionland: [],   // 征地
                hasGendi: 1,
                hasLindi: 1,
                arableLand: [],        // 土地
                lindi: [],        // 林地
                gendi: [],        // 耕地
                refarmingInfoList: [],   // 复垦情况
                houseBaseInfoList: [],   // 房屋情况
            }
        },

        created() {
            if (this.familyid) {
                this.getBaseInfo();
                this.getLandTransferInfo();
                this.getRefarmingInfoList();
                this.getHouseBaseInfoList();
            }
        },
        watch: {},
        methods: {
            // 跳转编辑页面
            goDetail(index, item) {
                if (index > 0 && !this.familyid) {
                    this.$vux.toast.show({
                        text: '请填写基本信息',
                        type: 'text',
                        position: 'middle',
                    })
                    return;
                }

                switch (index) {
                    case 0:
                        this.$tools.goPage_query('editbaseInfo', {
                            familyid: this.familyid,
                            name: item.children[0].value,
                            idCardNumber: item.children[1].value,
                            familyNumber: item.children[2].value,
                            villageCode: !this.familyBaseInfo ? '' : this.familyBaseInfo.villagecode,
                            houseAddress: item.children[4].value,
                        })
                        break;
                    case 1:
                        this.$tools.goPage_query('editsdqtx', {
                            familyid: this.familyid,
                            drinkInfo: item.children[0].value,
                            powerInfo: item.children[1].value,
                            gasInfo: item.children[2].value,
                            loadInfo: item.children[3].value,
                            correspondInfo: item.children[4].value,
                        })
                        break;
                    case 2:
                        this.$tools.goPage_query('edittudi', {
                            familyid: this.familyid,
                            villagecode: this.familyBaseInfo.villagecode,
                            id: item.id,
                            landarea: item.landarea,
                            transferarea: item.transferarea,
                            transfertype: item.transfertype,
                            expropriationtime: item.expropriationtime,
                            transferoffset: item.transferoffset,
                            landdirection: item.landdirection,
                            hasGendi: this.gendi.length && item.id === this.gendi[0].id ? 1 : this.gendi.length ? 0 : 1,
                            hasLindi: this.lindi.length && item.id === this.lindi[0].id ? 1 : this.lindi.length ? 0 : 1,
                        })
                        break;
                    case 3:
                        this.$tools.goPage_query('editzhengdi', {
                            familyid: this.familyid,
                            villagecode: this.familyBaseInfo.villagecode,
                            id: item.id,
                            landarea: item.landarea,
                            expropriationtime: item.expropriationtime,
                            offsetsenttime: item.offsetsenttime,
                            expropriationoffset: item.expropriationoffset,
                        })
                        break;
                    case 4:
                        this.$tools.goPage_query('editfuken', {
                            familyid: this.familyid,
                            villagecode: this.familyBaseInfo.villagecode,
                            id: item.id,
                            refarmingarea: item.refarmingarea,
                            refarmingregion: item.refarmingregion,
                            destroyreason: item.destroyreason,
                            refarmingamount: item.refarmingamount,
                            sendtime: item.sendtime,
                        })
                        break;
                    case 5:
                        this.$tools.goPage_query('edithouse', {
                            familyid: this.familyid,
                            villagecode: this.familyBaseInfo.villagecode,
                            id: item.id,
                            housetype: item.housetype,
                            housearea: item.housearea,
                            examinetime: item.examinetime,
                            examinearea: item.examinearea,
                            examinenumber: item.examinenumber,
                            buildingtime: item.buildingtime,
                            dilapidatedlevel: item.dilapidatedlevel,
                            isdilapidated: item.isdilapidated,
                            hadsendreformcost: item.hadsendreformcost,
                            reformamount: item.reformamount,
                            reformsendtime: item.reformsendtime,
                            reformfinish: item.reformfinish,
                            reformtime: item.reformtime,
                            propertyright: item.propertyright,
                            certificatesnumber: item.certificatesnumber,
                            acquisitiontime: item.acquisitiontime,
                            remarks: item.remarks,
                        })
                        break;
                    case 6:
                        this.$tools.goPage_query('editchanye', {
                            familyid: this.familyid,
                            villagecode: this.familyBaseInfo.villagecode,
                            hasGarden: item.children[0].value === '是' ? 1 : 0,
                            gardenarea: item.children[1].value ? item.children[1].value : '',
                            crop: item.children[2].value ? item.children[2].value : '',
                            gardengdp: item.children[3].value ? item.children[3].value : '',
                            hadbusiness: item.children[4].value === '是' ? 1 : 0,
                            businesscontent: item.children[5].value ? item.children[5].value : '',
                            bednumber: item.children[6].value ? item.children[6].value : '',
                            businessgdp: item.children[7].value ? item.children[7].value : '',
                        })
                        break;
                }

            },

            // 获取户基本信息
            getBaseInfo() {
                // getFamilyInfoById
                let _param = this.$tools.invokeUAF('resident/getFamilyInfoById', {
                    familyId: this.familyid
                })
                resident.getFamilyInfoById(_param).then(res => {

                    let data = res.data.data.familyBaseInfo;
                    this.familyBaseInfo = data;

                    this.lists.forEach((item, index) => {
                        if (index === 0 || index === 1 || index === 6) {
                            item.children.forEach((i, j) => {
                                i.value = i.key === 'hasgarden' || i.key === 'hadbusiness' ? data[i.key] === 1
                                    ? '是' : '否' : data[i.key];
                            })
                        }
                    })
                })
            },

            // 获取土地和征地情况
            getLandTransferInfo() {
                this.hasGendi = 1;
                this.hasLindi = 1;
                let _param = this.$tools.invokeUAF('resident/getFamilyLandTransferInfo', {
                    familyId: this.familyid
                })
                resident.getFamilyLandTransferInfo(_param).then(res => {
                    let data = res.data.data;
                    this.requisitionland = data.zhengdi;   // 征地
                    this.arableLand = [...data.gengdi, ...data.lindi];        // 耕地
                    this.lindi = data.lindi;       // 林地
                    this.gendi = data.gengdi;
                    // for (let i in this.arableLand) {
                    //     if (this.arableLand[i].transfertype === 1) {
                    //         this.hasGendi = 0;
                    //     }
                    //     if (this.arableLand[i].transfertype === 2) {
                    //         this.hasLindi = 0;
                    //     }
                    // }
                })
            },

            // 获取复垦情况
            getRefarmingInfoList() {
                let _param = this.$tools.invokeUAF('resident/getRefarmingInfoList', {
                    familyId: this.familyid
                })
                resident.getRefarmingInfoList(_param).then(res => {

                    let data = res.data.data;
                    this.refarmingInfoList = data;
                })
            },

            // 获取房屋情况
            getHouseBaseInfoList() {
                let _param = this.$tools.invokeUAF('resident/getHouseBaseInfoList', {
                    familyId: this.familyid
                })
                resident.getHouseBaseInfoList(_param).then(res => {
                    let data = res.data.data;
                    this.houseBaseInfoList = data;

                })
            },

            // 删除
            deleteInfo(kid, item) {
                this.isShowDeleteDialog = true;
                this.kid = kid;
                this.deleteId = item.id;
            },

            onCancel() {
                this.isShowDeleteDialog = false;
                this.kid = '';
                this.deleteId = '';
            },

            onConfirm() {
                if (this.kid === 'arableLand') {
                    let _param = this.$tools.invokeUAF('resident/deleteLandTransferInfo', {
                        id: this.deleteId,
                    })
                    resident.deleteLandTransferInfo(_param).then(res => {
                        if (res.data.code === '0') {
                            this.getLandTransferInfo();
                        }
                    })
                } else if (this.kid === 'requisitionland') {
                    let _param = this.$tools.invokeUAF('resident/deleteIssueInfo', {
                        id: this.deleteId,
                    })
                    resident.deleteIssueInfo(_param).then(res => {
                        if (res.data.code === '0') {
                            this.getIssueInfoList();
                        }
                    })
                } else if (this.kid === 'refarmingInfoList') {
                    let _param = this.$tools.invokeUAF('resident/deleteRefarmingInfo', {
                        id: this.deleteId,
                    })
                    resident.deleteRefarmingInfo(_param).then(res => {
                        if (res.data.code === '0') {
                            this.getRefarmingInfoList();
                        }
                    })
                } else {

                    let _param = this.$tools.invokeUAF('resident/deleteHouseBaseInfo', {
                        id: this.deleteId,
                    })
                    resident.deleteHouseBaseInfo(_param).then(res => {
                        if (res.data.code === '0') {
                            this.getHouseBaseInfoList();
                        }
                    })
                }
            },

        },
    };
</script>

<style lang="less" rel="stylesheet/less" type="text/less">
    .page_accoutInfo {
        .every-info {
            .info-title {
                height: 1rem;
                line-height: 1rem;
                border-bottom: 1px solid #f4f4f4;
                margin-top: 10px;
                background-color: #fff;

                img {
                    width: .5rem;
                    vertical-align: middle;
                }

                .title-text {
                    width: 85%;
                    text-align: center;
                }
            }

        }

        .land-btn {
            line-height: 1.5;
            font-size: 12px;
            color: #9e5e23 !important;
            background: #feeaca;
            border: 1px solid transparent;
            border-radius: 0.25rem;
            padding: 0px 15px;
            margin-right: 15px;
        }
    }
</style>
